<template>
	<view class="detail">
		<!-- 文章的标题 -->
		<view class="title">
			<B>{{exhibition.exhibitioTitel}}</B>
		</view>
		<view class="avatar">
			<image :src="exhibition.eventPoster"></image>
		</view>
		
		<!-- 文章副标题 -->
		<view class="info">
			参展画家：{{exhibition.exhibitionPainter}}
		</view>
		<view class="info">
			活动状态: {{stateName}}
		</view>
		<view class="info">
			开展时间: {{exhibition.startTime}}  到 {{exhibition.endTime}}
		</view>

		<!-- 页眉 -->
		<view class="info">
			<!-- 作者 -->
			<view class="author">
				编辑：{{exhibition.createByLabel}}
			</view>
			<!-- 时间 -->
			<view class="time">
				发布日期：{{exhibition.createTime}}
			</view>
		</view>
		
		<!-- 主体内容-->
		<view class="content">
			<!-- 使用富文本标签，将html代码解析出来 -->
			<rich-text :nodes="exhibition.exhibitionDescribe"></rich-text>
		</view>

		<!-- 主体内容 -->
		<view class="hot_goods">
			<view class="tit">代表作品</view>
			
			<!-- 代表作品 -->
			<view class="goods_list">
				<view v-for="(item, index) in listWorking">
				<!-- 代表作品 -->
				<view class="goods_item">
                    <image :src="item.pictureUrl"></image>
					
					<view class="name">
						{{index+1}}.{{item.title}}
					</view>
				</view>
				</view>
			</view>
			
			<view class="tit">视频介绍</view>
			<!-- 视频开始 -->
			<view class="video-section">
				<video id="myVideo" class="video" src="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/wap2appvsnative.mp4" @error="videoErrorCallback" :danmu-list="danmuList"
				    enable-danmu danmu-btn controls>
			    </video>
			</view>
			<!-- 视频结束 -->
		</view>

		<!-- 版权声明 -->
		<view class="desc">
			免责声明：本站的内容全部为原创内容，如果侵权请联系管理员（644415444@qq.com）进行整改删除，本站进行了内容采集不代表本站及其作者的观点，若有侵犯请及时联系管理员，感谢您的支持！
		</view>
		
		<view class="bottom"></view>
		<commonUserTabBar :currentTab="currentTab"></commonUserTabBar>
	</view>
</template>

<script>
import global from '@/global.js'

export default {
	data() {
		return {
			videoSrc: 'https://media.w3.org/2010/05/sintel/trailer.mp4', // 视频文件地址
			autoplay: true, // 是否自动播放
			//当前选项卡
			currentTab:'/pages/exhibitionList/specialDetail',
			listWorking:[],
			listArticle: [],
			id:'',
			exhibition:'',
			stateName:'',
			title: 'video',
			src: '',
			inputValue: '',
			danmuList: [{
								text: '第 1s 出现的弹幕',
								color: '#ff0000',
								time: 1
							},
							{
								text: '第 3s 出现的弹幕',
								color: '#ff00ff',
								time: 3
							}
						]
		};
	},
	computed:{
		videoHtml: function() {
			return `<video controls="controls" width="100%" height=300rpx;><source src="${this.videoSrc}" type="video/mp4"></video>`;
		}
	},
	methods: {
	fetchData(id) {
	  uni.request({
	    url: global.baseUrl + 'api/exhibition/' + id, // 接口地址
	    method:'get',
		dataType: "json",
		header: {
	    'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息
	    },
		success: (res) => {
			//console.log("request result data  :", res)
			if(res.data.code==0){
				this.exhibition=res.data.data
				this.stateName=res.data.data.statusLabel.label
				this.listWorking=res.data.data.listWorking
				this.listArticle=res.data.data.listArticle
				
			}else{
				
				console.log("request result error: " ,res.data.code)
			} 
	    },
	    fail: (error) => {
	      console.log(error)
	    }
	  })
	},
	bindInputBlur: function (e) {
				this.inputValue = e.target.value
			},
			bindButtonTap: function () {
				var that = this
				uni.chooseVideo({
					sourceType: ['album', 'camera'],
					maxDuration: 60,
					camera: ['front', 'back'],
					success: function (res) {
						this.src = res.tempFilePath
					}
				})
			},
			bindSendDanmu: function () {
				this.videoContext.sendDanmu({
					text: this.inputValue,
					color: this.getRandomColor()
				})
			},
			videoErrorCallback: function (e) {
				console.log('视频错误信息:')
				console.log(e.target.errMsg)
			},
			getRandomColor: function () {
				const rgb = []
				for (let i = 0; i < 3; ++i) {
					let color = Math.floor(Math.random() * 256).toString(16)
					color = color.length == 1 ? '0' + color : color
					rgb.push(color)
				}
				return '#' + rgb.join('')
			}
	
	},
	onReady: function (res) {
			this.videoContext = uni.createVideoContext('myVideo')
	},
	onLoad(option) {
	  console.log("onLoad option id :   ", option.id)
	  this.fetchData(option.id) // 在页面加载时调用fetchData方法获取数据
	  this.id=option.id
	}
	
};
</script>

<style lang="scss">
	.detail {
		padding: 30rpx;

		.title {
			font-size: 32rpx;
			color: #333;
		}
		.subheading{
			font-size: 30rpx;
			color: #333;
		}
		.avatar{
			background-color: #fff;
			margin: 10rpx 0;
			width: 100%;
			//防止盒子被撑大
			box-sizing: border-box;
			padding: 15rpx;
			image{
				width: 100%;
				height: 340px;
				//把图片设置成块元素，才让用margin设置居中
				display: block;
				margin: 0 auto;
			}
			
			}
		.info {
			background: #f6f6f6;
			padding: 20rpx 10rpx;
			font-size: 30rpx;
			color: #999;
			display: flex;
			justify-content: space-between;
			margin: 30rpx 0;
		}
		.content {
			padding-bottom: 50rpx;
			/deep/ img {
				width: 100%;
			}
		}

		// 声明
		.desc {
			background: #fef0f0;
			font-size: 26rpx;
			color: #f89898;
			padding: 30rpx;
			line-height: 1.8em;
		}
		
		.hot_goods{
			background-color: #eee;
			// 防止掉进子元素的margin里面
			overflow: hidden;
			margin-top: 10px;
			.tit{
				font-size: 35rpx;
				height: 50px;
				line-height: 50px;
				text-align: left;
				letter-spacing: 2px;
				color: #999;
				background-color: #fff;
				margin: 10rpx 0;
			}
			
			.goods_list{
				padding: 0 15rpx;
				//显示在一行
				display: flex;
				//自动换行
				flex-wrap: wrap;
				//两侧帖边对齐
				justify-content: space-between;
				
				.goods_item{
					background-color: #fff;
					margin: 10rpx 0;
					width: 100%;
					//防止盒子被撑大
					box-sizing: border-box;
					padding: 15rpx;
					image{
						width: 100%;
						height: 340px;
						//把图片设置成块元素，才让用margin设置居中
						display: block;
						margin: 0 auto;
					}
					.name{
						font-size: 28rpx;
						line-height: 50rpx;
						padding-bottom: 15rpx;
						padding-top: 10rpx;
					}
				}
			}
			
			.video-section{
				width: 100%;
				height: 300px;
				.video{
					align-items: center;
					width: 100%;
				}
			}
			
		}
		
	}
</style>
